/*
 * WidgetContainer.cpp
 *
 *	Author: stravant
 *	Description:
 *		
 */

#include "WidgetContainer.h"

namespace tbt {

void WidgetContainerAbsolute::onLayout() {
	auto pos = getPosition();
	auto size = getSize();

	//each child
	for (auto it = mChildren.begin(); it != mChildren.end(); ++it) {
		Ref<Widget> widget = (*it);
		auto dsize = widget->getDesiredSize();
		auto dpos = widget->getDesiredPosition();

		//final values
		int x, y, w, h;

		//x axis
		if (dpos.x() == Widget::kPositionAny) {
			x = pos.x();
			if (dsize.x() == Widget::kSizeAny) {
				w = size.x();
			} else {
				w = dsize.x();
			}
		} else {
			x = dpos.x();
			if (dsize.x() == Widget::kSizeAny) {
				w = size.x() - x;
			} else {
				w = dsize.x();
			}
		}

		//y axis
		if (dpos.y() == Widget::kPositionAny) {
			y = pos.y();
			if (dsize.y() == Widget::kSizeAny) {
				h = size.y();
			} else {
				h = dsize.y();
			}
		} else {
			y = dpos.y();
			if (dsize.y() == Widget::kSizeAny) {
				h = size.y() - y;
			} else {
				h = dsize.y();
			}
		}

		//set child values
		setChildBounds(widget, IRect(x, y, w, h));

		//layout child
		widget->performLayout();
	}
}

}




















